La idea de esat clase fue pensar el tradeoff entre descubrir las relaciones de las covariables y las variables explicativas, y por otro lado, la capacidad predictiva entre un modelo de ML por ejemplo.
install.packages("plotly")
install.packages("rgl")
install.packages("plot3D")
install.packages(tidyverse)
install.packages(dplyr)
install.packages(GGally)
library("plotly")
Loading required package: ggplot2
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
library("plot3D")
library(tidyverse) # entorno tidy
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
✓ tibble 3.1.6 ✓ dplyr 1.0.7
✓ tidyr 1.1.4 ✓ stringr 1.4.0
✓ readr 2.1.2 ✓ forcats 0.5.1
✓ purrr 0.3.4
── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks plotly::filter(), stats::filter()
x dplyr::lag() masks stats::lag()
library(dplyr) # manejo de datos
library(GGally) # scatterplots multiples
Registered S3 method overwritten by 'GGally':
method from
+.gg ggplot2
library(rgl) # para graficos 3D
This build of rgl does not include OpenGL functions. Use
rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).
df = read.csv("datos_alquiler_crossvalidation.csv", stringsAsFactors = F)
bootstrap=function(dataset, formula, sizeGroup, amountOfGroups){
coeficientes=list()
for (i in 1:amountOfGroups) {
grupo = dataset[sample(nrow(dataset), sizeGroup, replace = T), ]
modeloActual = lm(formula, data = grupo)
coeficiente = list(modeloActual$coefficients)
coeficientes[i] = coeficiente
}
return(coeficientes)
}
formu = formula(price~surface_covered+fondo)
l = bootstrap(df, formu, 10, 10000)
mu = c()
alpha = c()
beta = c()
for (i in 1:length(l)) {
mu[i] = l[[i]][1]
alpha[i] = l[[i]][2]
beta[i] = l[[i]][3]
}
fig <- plot_ly(x=~beta, y=~alpha, z=~mu, type="scatter3d", mode="markers",xlab = 'beta (fondo)', ylab= 'alpha (sur cov)', zlab = 'mu (intercept)', size = 1)
fig <- fig %>% layout(title = 'Bootsrap',
xaxis = list(title = 'beta',
zeroline = TRUE,
range = c(0, 250)),
yaxis = list(title = 'Alpha',
range = c(0,1400)))
fig
Warning: 'scatter3d' objects don't have these attributes: 'xlab', 'ylab', 'zlab'
Valid attributes include:
'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Warning: 'scatter3d' objects don't have these attributes: 'xlab', 'ylab', 'zlab'
Valid attributes include:
'connectgaps', 'customdata', 'customdatasrc', 'error_x', 'error_y', 'error_z', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'legendgroup', 'legendgrouptitle', 'legendrank', 'line', 'marker', 'meta', 'metasrc', 'mode', 'name', 'opacity', 'projection', 'scene', 'showlegend', 'stream', 'surfaceaxis', 'surfacecolor', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'visible', 'x', 'xcalendar', 'xhoverformat', 'xsrc', 'y', 'ycalendar', 'yhoverformat', 'ysrc', 'z', 'zcalendar', 'zhoverformat', 'zsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
mean(mu)
[1] 2836.538
mean(alpha)
[1] 276.2949
mean(beta)
[1] 38.44521
lm(formu, data = df)$coefficients
(Intercept) surface_covered fondo
2799.94910 274.71754 36.46581